package me.zk.practice1.hw;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/8/9 16:30
 */
public class HWBJ56 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        if (s.length()%5!=0) {
            System.out.println(-1);
            return;
        }

        int[] tags = new int[4];
        Map<Character,Integer> map = new HashMap<>();
        map.put('q',0);
        map.put('u',1);
        map.put('a',2);
        map.put('c',3);
        map.put('k',4);

        int num=0;
        int res=0;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            int t = map.get(ch);

            if (t==0){
                //
                tags[t]++;
                num++;
                if (num > res) {
                    res = num;
                }

            } else {
                if (tags[t-1]==0) {
                    System.out.println(-1);
                    return;
                } else {
                    tags[t-1]--;
                    if (t==4){
                        num--;
                    } else {
                        tags[t]++;
                    }

                }

            }

        }
        if (num != 0) {
            System.out.println(-1);
        } else {
            System.out.println(res);
        }
    }
}
